package net.jalbum.filters.components;

import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import javax.swing.JTextField;
import javax.swing.text.Document;

/**
 * JTextField that fires an ActionPerformed event as soon as focus is lost
 * @author david
 */
public class JInstantTextField extends JTextField {

    public JInstantTextField(Document doc, String text, int columns) {
        super(doc, text, columns);
        init();
    }

    public JInstantTextField(String text, int columns) {
        super(text, columns);
        init();
    }

    public JInstantTextField(int columns) {
        super(columns);
        init();
    }

    public JInstantTextField(String text) {
        super(text);
        init();
    }

    public JInstantTextField() {
        init();
    }

    private void init() {
        addFocusListener(new FocusListener() {
            public void focusLost(FocusEvent e) {
                fireActionPerformed();
            }
            public void focusGained(FocusEvent e) {
            }
        });
    }
}
